/*
 *说明：认证方式信息表 首页脚本
 *
 *@author mlc 2012-11-27
*/

var opeForm;
var grid;

$(function(){

	opeForm = $('#opeForm');

	grid=$('#listTable').datagrid({
		frozenColumns:[[
            {title:'选择',field:'ck',checkbox:true}
		]],
		columns:[[

            {title:'认证方式代码',field:'auth_mode_code',align:'center',width:80},

            {title:'认证方式名称',field:'auth_mode_name',align:'center',width:80},

            {title:'允许访问的最高账号类型',field:'acc_type_decode',align:'center',width:80},

            {title:'默认方式',field:'is_default',align:'center',width:80,
            	formatter:function(value, rec){
            		return value == '1' ? '<font color="green"> √ </font>' : '<font color="red"> × </font>';
            	}		
            },

            {title:'是否启用',field:'use_status',align:'center',width:80,
            	formatter:function(value, rec){
            		return value == '1' ? '启用 ' : '停用';
            	}		
            },
            
            {title:'序号',field:'auth_seq',align:'center',width:80},

            {title:'描述',field:'auth_mode_desc',align:'center',width:80}
            
        ]]
	});

	queryOperation();

	$('#queryBtn').click(queryOperation);
	$('#clearBtn').click(clearOperation);
	$('#reloadBtn').click(refreshWin);
	$('#addBtn').click(addOperation);
	$('#editBtn').click(editOperation);
	$('#deleteBtn').click(deleteOperation);
	$('#genReportBtnCmd').click(genReportOperation);
});

//翻页时自动调用此函数
function onLoadPrev(msg){

	var queryParams=grid.datagrid('options').queryParams;
	queryParams['firstQuery']=false;
}

//查询操作
function queryOperation(){

	var params = opeForm.serializeObject();
	grid.datagrid("options").pageNumber = 1;
	grid.datagrid({
		url: 'B_AUTH_MODE!showList.do',
		queryParams: jQuery.extend({}, params, {'firstQuery': true})
	});
}

//清空操作（重置）
function clearOperation() {
	opeForm.resetForm();
}

//查看明细
function showInfo(fid) {

	var href = 'B_AUTH_MODE!showInfo.do?model.key=' + fid;
	openWin(href,'pop',editWindowWidth,editWindowHeight); 
}

//添加认证方式信息表
function addOperation(){  

	var href = 'B_AUTH_MODE!showAdd.do';
	openWin(href,'pop');
}

//编辑认证方式信息表
function editOperation(){  

	var rows = grid.datagrid('getSelections');

	if (rows.length == 0) {
		showInfoWin('请您首先选中一条记录!');
		return;
	}  

	if (rows.length > 1) {
		showInfoWin('只能选择一条记录');
      	return; 
	}

	var href = 'B_AUTH_MODE!showEdit.do?id=' + rows[0].key;
	openWin(href,'pop');
}   

//删除认证方式信息表
function deleteOperation() {

	var rows = grid.datagrid('getSelections');

	if (rows.length == 0) {
		showInfoWin('请您首先选中要删除的记录!');	
		return;
	}

	var ids = [];

	for (var i = 0; i < rows.length; i++) {
		ids.push(rows[i].key);
	}

	var params = $ .param({'id' : ids}, true);

	$ .messager.confirm('提示信息', '您确定要删除选定的' + rows.length + '条记录吗?', function(result){
		if(result){
			$ .ajax({
				url: 'B_AUTH_MODE!doDelete.do',
				data: params,
				type: 'post',
				success: function(data){
				    showInfoWin('操作成功!');
					afterOK();
				}
			});
		}	
	});
}

//生成帐号密码策略报表
function genReportOperation(){
	opeForm.attr('action', 'B_AUTH_MODE!genAuthModeReport.do');
	opeForm.submit();
}

//操作成功后刷新列表
function afterOK(){

	queryOperation();
}